package com.service.admin.merchant.controller;

import com.service.admin.framework.log.RequestLog;
import com.service.admin.merchant.controller.rep.MerchantPageRep;
import com.service.admin.merchant.controller.req.MerchantAuditReq;
import com.service.admin.merchant.controller.req.MerchantPageReq;
import com.service.admin.merchant.service.MerchantService;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.enums.MerchantEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 商家信息表
 *
 * @author xxxx
 * @email xxxx@qq.com
 * @date 2020-03-28 12:54:56
 */
@RestController
@RequestMapping("merchant")
public class MerchantController extends BaseController {
    @Autowired
    private MerchantService merchantService;

    @PostMapping("page")
    @RequestLog("商家信息分页查询")
    public PageResponse<MerchantPageRep> page(@RequestBody MerchantPageReq pageReq) {
        return successQueryPageResponse(merchantService.page(pageReq));
    }

    @PostMapping("audit/{id}")
    @RequestLog("审核商家申请入驻")
    public BaseResponse audit(@PathVariable("id") Integer id, @RequestBody MerchantAuditReq auditReq) {
        merchantService.audit(id, auditReq);
        return successBaseResponse();
    }

    @PostMapping("freeze-batch")
    @RequestLog("批量冻结商家")
    public BaseResponse freeze(@RequestBody Integer[] ids) {
        merchantService.batchUpdateMerchantStatus(ids, MerchantEnums.Status.frost);
        return successBaseResponse();
    }

    @PostMapping("unfreeze-batch")
    @RequestLog("批量解冻商家")
    public BaseResponse unfreeze(@RequestBody Integer[] ids) {
        merchantService.batchUpdateMerchantStatus(ids, MerchantEnums.Status.in_business);
        return successBaseResponse();
    }


}
